// DBDataManager.h: interface for the CDBDataManager class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#if !defined(AFX_DBDATAMANAGER_H__712903BF_C09F_4D4A_A773_CC7E061DC223__INCLUDED_)
#define AFX_DBDATAMANAGER_H__712903BF_C09F_4D4A_A773_CC7E061DC223__INCLUDED_ 

#include "EntityDefine.h"
#include "AFXTEMPL.H"
#include "ADODatabase.h"
#include "ADORecordset.h"
#include "ADOCommand.h" 

typedef void(*pUpdateAcc)(lpAccount pAcc,void*);
class CDBDataManager  
{
private: 
	HANDLE	m_hSyn;
	static CDBDataManager* m_pInstance; 
	CArray<lpScript,lpScript> m_arrScript;
	CArray<lpServer,lpServer> m_arrServer;
	CADODatabase m_adoDataBase;
	CString m_strConneString;
	BOOL	m_bRefreshRunning;
	pUpdateAcc m_UpdateAccdCB;
	void* m_pParent;
	inline void UpdateAccCB(lpAccount pAcc)
	{
		if(m_UpdateAccdCB!=NULL)
		{
			m_UpdateAccdCB(pAcc,m_pParent);
		}
	};
public: 
	HANDLE	m_hLoginHandle;
	CDBDataManager();
	static CDBDataManager* CreateInstance();
	virtual ~CDBDataManager();
	inline void SetUpdateAccCB(pUpdateAcc pUpdateAccCB,void* pParent)
	{
		m_pParent=pParent;
		m_UpdateAccdCB=pUpdateAccCB;
	}
	inline BOOL IsRefreshRunning()
	{
		return m_bRefreshRunning;
	}
	void StartRoleSynInfo();
	void ClearAll();
	void LoadData();
	lpAccount FindAccByID(int iAccID);
	lpScript FindScriptByID(int iScriptID);
	lpServer FindServerByID(int iServerID);

	
	int UpdateAcc(lpAccount pAcc);
	int UpdateScript(lpScript pScript);
	int UpdateServer(lpServer pServer);

	int BoundServerList(CComboBox* lpCmb);
	int BoundScriptList(CComboBox* lpCmb);
	int SelectCMBItemByData(CComboBox* lpCmb,int iData);
	int GetNewID(CString strTableName);
	BOOL DeleteByDataID(int iIDData,CString strTableName);
	CArray<lpAccount,lpAccount> m_arrAcc;

private:
	static DWORD WINAPI RefreshDataThread(void* pParam); //Refresh Thread
};
#endif // !defined(AFX_DBDATAMANAGER_H__712903BF_C09F_4D4A_A773_CC7E061DC223__INCLUDED_)
